clear all;close all;clc

Hard0_Soft1 =1
figure('position',[100 100 800 450]);
for SNR = 1:2
    % ===
    R_Soft_control_noise_Cond1 = [37/100 27/100 31/100 34/100 71/100 65/100 70/100 64/100]; % left -60, right +60

    R_Soft_noise_Cond1 = [97/100 97/100 96/100 98/100 98/100 97/100 99/100 95/100]; % % left -60, right +60

    R_Soft_noise_Cond2 = [97/100 100/100 95/100 100/100 99/100 96/100 97/100 95/100]; % % left -15, right +15

    R_Soft_noise_Cond3 = [97/100 95/100 95/100 95/100 100/100 96/100 96/100 97/100]; % % 0, right +5

    R_Soft_noise_Cond4 = [31/100 27/100 33/100 37/100 72/100 35/100 38/100 64/100]; % % Right +85, right +90

    R_Soft_noise_Cond5 = [79/100 71/100 75/100 72/100 86/100 79/100 71/100 80/100]; % % Right +75, right +105

    R_Soft_noise_Cond6 = [90/100 96/100 96/100 92/100 98/100 97/100 99/100 94/100]; % % Back 180, 175

    titles={'A. S1, Front, −60^{o}&+60^{o}','B. S1, Front, −15^{o}&+15^{o}','C. S1, Front, 0^{o}&+5^{o}','D. S1, Side, +85^{o}&+90^{o}','E. S1, Side, +65^{o}&+90^{o}','F. S1, Back, +180^{o}&+175^{o}'};

    n=100;
    alpha=0.05;
    outP=f_out_plot;
    %     mean(R_control_noise_Cond1)
    for i=1:6
        subplot('position',outP(i,:))
        if Hard0_Soft1==0
            eval(['tem = R_Processed_noise_Cond' num2str(i) ';'])
        elseif Hard0_Soft1==1
            eval(['tem = R_Soft_noise_Cond' num2str(i) ';'])
        end
        pbar = [R_Soft_control_noise_Cond1' tem' ].*100;
        mean(tem)
        if SNR == 1
            c=bar(pbar(1:4,:));hold on;
            c(1).FaceColor = [0        0.447        0.741];
            c(2).FaceColor = [ 0.85        0.325        0.098];
        else
            dd=bar(5:8,pbar(5:8,:))
            dd(1).FaceColor = [0.2        0.5        0.341];
            dd(2).FaceColor = [ 0.95        0.625        0.298];

            %         pause7

            for icond = 1:2
                for ib = 1:length(pbar)
                    CI(icond,ib) = f_confid_I(n,pbar(ib,icond)./100,alpha).*100;
                end
                hold on;
                errorbar((1:8)+0.3.*(icond-1.5),pbar(:,icond),CI(icond,:),'k.');
            end
            set(gca,'xtick',1:8)

            xlabel('Sentence Group #');
            ylabel('Percent Correct (%)')
            box off;
            ylim([0 115])
            title(titles{i})
            if i==2
                %             if Hard0_Soft1==0
                %                 t=text(5,145,['HRTF-1, Hard Mask, SNR = 0 dB'],'horizontalalignment','center');set(t,'fontsize',12)
                %             else
                t=text(5,145,['HRTF-3, Soft Mask, SNR = 0 or 3 dB'],'horizontalalignment','center');set(t,'fontsize',12)
                %             end
            end
            for igroup = 1:8
                p1=pbar(igroup,1)./100;
                p2=pbar(igroup,2)./100;
                out = f_ztest(p1,p2,100,100);
                if out.p < 0.05/6 & p1<p2
                    plot(igroup-0.1,max(pbar(igroup,:))+CI(1,igroup)+4,'k*');
                end
            end
            if i==4
                hh=legend('Control, 0 dB','Processed, 0 dB','Control, 3 dB','Processed, 3 dB')
                hh.Position = [0.08 0.3 0.1 0.1]
                hh.IconColumnWidth  = 6
                legend boxoff
            end
        end
    end

    if Hard0_Soft1==0
        exportgraphics(gcf, 'BB_S3_Figure6_HardResults.png', 'Resolution', 600,'ContentType', 'vector')
    elseif Hard0_Soft1==1
        exportgraphics(gcf, 'BB_S3_Figure11_SoftResults.png', 'Resolution', 600,'ContentType', 'vector')
    end

end